<?php
/**********************************************************************//**\file
	Armory Wowarmory Data

	Description:  Wowarmory data model, provides a consistent interface to guild
		information pulled from wowarmory.com.
*******************************************************************************/

	class wowarmorydata
	{
		protected $players = array();
		
		public function __construct()
		{
			
		}

		public function add_player($name, $rank, $url)
		{
			$this->players[] = array(
				'name' => $name,
				'rank' => $rank,
				'url' => $url
			);
		}

		public function store()
		{
			$db = new armorydb();

			foreach($this->players as $var)
			{
				$time = time();

				# Check to see whether a record exists for this player
				$db->query("SELECT player_name FROM armory_player WHERE player_name = '{$var['name']}'");

				if(is_null($db->result()))
				{
					# Create a new record
					$db->query("INSERT INTO armory_player SET player_name = '{$var['name']}', player_added = $time, player_updated = 0, player_rank = {$var['rank']}, player_url = '{$var['url']}'");
				}
				else
				{
					# Update extant record
					$db->query("UPDATE armory_player SET player_rank = {$var['rank']}, player_url = '{$var['url']}' WHERE player_name = '{$var['name']}'");
				}
			}

			unset($db);
		}


		public function debug()
		{
			var_dump($this->players);
		}
	}
?>
